
<?
	  	  include("/inc/header.html") {}
    ?>
<div class="col-lg-4">
	<div class="panel" style="height: 380px; overflow: auto;">
		<div class="panel-body">
		<div style="margin-left: 10px;">
			<button style="height: 35px;width: 55px;" type="button" class="btn btn-blue btn-xs" onclick="quanxuan()"><h5>全选</h5></button>
			<button style="height: 35px;width: 70px;" type="button" class="btn btn-blue btn-xs" onclick="quxiaoquanxuan()"><h5>取消全选</h5></button>
			
			</div>
		    &nbsp; &nbsp; &nbsp;
			<ul id="tree" class="ztree" style="width:300px"; overflow:auto;"></ul>
		</div>	
	</div>
</div>

<script>
function getQueryString(name) { 
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r != null) return unescape(r[2]); return null; 
	} 
var winName=getQueryString("winName");
  var classid='';
  var classname='';
	$(function() {
		initTree();
	});
	function initTree() {
		$.ajax({
			type : "post",
			data : {},
			url : "./KnowledgeclassListall.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable: true,
				//nocheckInherit: true
				chkboxType: {"Y":"s", "N":"s"}
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠

	}
	
	function onClick(e, treeId, treeNode) {
		//classid = treeNode.id;		
		//classname=treeNode.name;  
	}
	
		function  save(){
		var treeObj = $.fn.zTree.getZTreeObj("tree");
			var checkedNode = treeObj.getCheckedNodes(); 
			for(var i=0;i<checkedNode.length;i++){
				if(checkedNode[i].id!=null){
					classid+=checkedNode[i].id+";";
					classname+=checkedNode[i].name+";";
				}
			}
		if(classid==null){
		var index = parent.layer.getFrameIndex(window.name); 
		window.parent.window[winName].$("#parentClassid").val("0");
	  	 window.parent.window[winName].$("#parentclassname").val("根节点");
		 parent.layer.close(index);
		}else{
		var index = parent.layer.getFrameIndex(window.name); 
	   	window.parent.window[winName].$("#parentClassid").val(classid);
	    window.parent.window[winName].$("#parentclassname").val(classname);
	    parent.layer.close(index);
	    }
     }
	
	function qingling(){
	var index = parent.layer.getFrameIndex(window.name); 
		window.parent.window[winName].$("#parentClassid").val("0");
	    window.parent.window[winName].$("#parentclassname").val("根节点");
		 parent.layer.close(index);
	}
	function quanxuan(){
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var nodes = treeObj.getNodes();
		for (var i=0, l=nodes.length; i < l; i++) {
			treeObj.checkNode(nodes[i], true, true);
		}
	}
	function quxiaoquanxuan(){
	var treeObj = $.fn.zTree.getZTreeObj("tree");
	treeObj.checkAllNodes(false);
	}
</script>



